#include <stdlib.h>
#include <stdio.h>
#include <SDL.h>

int reponse(SDL_Rect position, SDL_Rect positio, SDL_Rect positi)
 {
     int continuer = 1;
     SDL_Event event;
     while(continuer)
     {
     SDL_PollEvent(&event);
     switch(event.type)
     {
     case SDL_QUIT:
     continuer = 0;
     break;
     case SDL_MOUSEBUTTONDOWN:
     if(event.button.x >= position.x && event.button.x <= (position.x + position.w) && event.button.y >= position.y && event.button.y <= (position.y + position.h))
     {
     return 1;
     continuer = 0;
     }
     if(positio.x != NULL && positio.h != NULL)
     if(event.button.x >= positio.x && event.button.x <= (positio.x + positio.w) && event.button.y >= positio.y && event.button.y <= (positio.y + positio.h))
     {
     return 2;
     continuer = 0;
     }
     if(positi.x != NULL && positi.h != NULL)
     if(event.button.x >= positi.x && event.button.x <= (positi.x + positi.w) && event.button.y >= positi.y && event.button.y <= (positi.y + positi.h))
     {
     return 3;
     continuer = 0;
     }
     break;
     }
     }
 }

SDL_Rect creabouton(int positionx, int positiony, int w, int h, SDL_Surface* ecran, int couleura, int couleurb, int couleurc, SDL_Surface *bouton)
{
    int continuer = 1, i = 0, resultat = 0, j = 0, resultat2 = 0, j2 = 0;
    SDL_Event event;
    SDL_Surface *degrader = NULL;
    SDL_Rect position, position2;
    position.x = positionx;
    position.y = positiony;
    position.w = w;
    position.h = h;
    position2.x = positionx;
    position2.y = positiony;

    bouton = SDL_CreateRGBSurface(SDL_HWSURFACE, w, h, 32, 0, 0, 0, 0);
    SDL_FillRect(bouton, NULL,  SDL_MapRGB(ecran->format, couleura, couleurb, couleurc));
    SDL_BlitSurface(bouton, NULL, ecran, &position);
    resultat2 = (10*h)/100;
    resultat = (8*w)/100;
    for(i = 0; i < resultat || i < resultat2; i++)
    {
      if(i < resultat)
      {
      degrader = SDL_CreateRGBSurface(SDL_HWSURFACE, 1, h, 32, 0, 0, 0,0);
      SDL_FillRect(degrader, NULL, SDL_MapRGB(ecran->format, j, j, j));
      SDL_BlitSurface(degrader, NULL, ecran, &position);
      position.x++;
      j += 255/resultat;
      }
      if(i < resultat2)
      {
      degrader = SDL_CreateRGBSurface(SDL_HWSURFACE, w, 1, 32, 0, 0, 0,0);
      SDL_FillRect(degrader, NULL, SDL_MapRGB(ecran->format, j2, j2, j2));
      SDL_BlitSurface(degrader, NULL, ecran, &position2);
      position2.y++;
      j2 += 255/resultat2;
      }
    }



    // code a venir
    position.x = positionx;
    position.y = positiony;
    position.w = w;
    position.h = h;
    SDL_Flip(ecran);
    return position;
}

